import request from '@/utils/request'
import {deepClone} from "@/utils/index.js";
const formatPageParams = (params)=>{
  const tempParams = deepClone(params);
  const query = {
    pageSize: tempParams.pageSize,
    pageNum: tempParams?.pageNum,
  };
  delete tempParams.pageSize;
  delete tempParams.pageNum;
  return {
    entity: tempParams,
    query
  };
}

// 查询模板列表
export function listModelInfo(query) {
  return request({
    url: '/flow/bpmnDesigner/prod/api/modelList',
    method: 'post',
    params: query
  })
}
// 查询模板列表
export function modelPage(query) {
  const data = formatPageParams(query);
  return request({
    url: '/flow/bpmnDesigner/prod/api/modelPage',
    method: 'post',
    data: data
  })
}
// 查询模板列表
export function deployBpmnModel(params) {
  return request({
    url: `/flow/bpmnDesigner/prod/api/deploy/${params.id}`,
    method: 'post'
  })
}

// 查询我的流程实例列表
export function queryMyProcessInstance(query) {
  const data = formatPageParams(query);
  return request({
    url: '/flow/prod/api/queryMyProcessInstance',
    method: 'post',
    data
  })
}

// 根据modelKey查询
export function getBpmnByModelKey(query) {
  return request({
    url: `/flow/bpmnDesigner/prod/api/getBpmnByModelKey/${query.modelKey}`,
    method: 'get'
  })
}

// 根据modelKey查询
export function getBpmnByModelId(query) {
  return request({
    url: `/flow/bpmnDesigner/prod/api/getBpmnByModelId/${query.modelId}`,
    method: 'get'
  })
}


// 根据modelKey查询
export function saveBpmnModel(data) {
  return request({
    url: `/flow/bpmnDesigner/prod/api/saveBpmnModel`,
    method: 'post',
    data
  })
}

// 初始化模板
export function initStartEventBpmn(data) {
  return request({
    url: `/flow/bpmnDesigner/prod/api/initStartEventBpmn`,
    method: 'post',
    data
  })
}

// 查询我的任务列表
export function queryApplyingTask(query) {
  const data = formatPageParams(query);
  return request({
    url: `/flow/prod/api/queryApplyingTask`,
    method: 'post',
    data
  })
}

// 查询我的已办列表
export function queryApplyedTask(query) {
  const data = formatPageParams(query);
  return request({
    url: `/flow/prod/api/queryApplyedTask`,
    method: 'post',
    data
  })
}

// 查询所有分类树列表
export function getCategories(data) {
  return request({
    url: `/flow/prod/api/getCategories`,
    method: 'post',
    data
  })
}

// 审批操作相关

export function setAssignee(query) {
  return request({
    url: `/flow/prod/api/setAssignee/${query.taskId}/${query.userCode}`,
    method: 'post'
  })
}
//   AfterAddSign : '/flow/prod/api/afterAddSign',
export function afterAddSign(data) {
  return request({
    url: `/flow/prod/api/afterAddSign`,
    method: 'post',
    data
  })
}

//   BeforeAddSign : '/flow/prod/api/beforeAddSign',
export function beforeAddSign(data) {
  return request({
    url: `/flow/prod/api/beforeAddSign`,
    method: 'post',
    data
  })
}
//   UnClaimTask : '/flow/prod/api/unClaimTask',
export function unClaimTask(data) {
  return request({
    url: `/flow/prod/api/unClaimTask`,
    method: 'post',
    data
  })
}
//   ClaimTask : '/flow/prod/api/claimTask',
export function claimTask(data) {
  return request({
    url: `/flow/prod/api/claimTask`,
    method: 'post',
    data
  })
}
//   HoldTask : '/flow/prod/api/holdTask',
export function holdTask(data) {
  return request({
    url: `/flow/prod/api/holdTask`,
    method: 'post',
    data
  })
}
//   TurnTask : '/flow/prod/api/turnTask',
export function backToStep(data) {
  return request({
    url: `/flow/prod/api/backToStep`,
    method: 'post',
    data
  })
}
//   DelegateTask : '/flow/prod/api/delegateTask',
export function delegateTask(data) {
  return request({
    url: `/flow/prod/api/delegateTask`,
    method: 'post',
    data
  })
}
//   TransferTask : '/flow/prod/api/transferTask',
export function transferTask(data) {
  return request({
    url: `/flow/prod/api/transferTask`,
    method: 'post',
    data
  })
}
//   RevokeProcess : '/flow/prod/api/revokeProcess',
export function revokeProcess(data) {
  return request({
    url: `/flow/prod/api/revokeProcess`,
    method: 'post',
    data
  })
}
//   StopProcess : '/flow/prod/api/stopProcess',
export function stopProcess(data) {
  return request({
    url: `/flow/prod/api/stopProcess`,
    method: 'post',
    data
  })
}

// 审批操作相关
export function completeTask(params) {
  return request({
    method: "POST",
    url: '/flow/prod/api/completeTask',
    data: params,
  });
}

//   RestartProcessInstance : '/flow/prod/api/restartProcessInstance',
export function restartProcessInstance(data) {
  return request({
    url: `/flow/prod/api/restartProcessInstance`,
    method: 'post',
    data
  })
}
//   FindBackNodesByTaskId : '/flow/prod/api/findBackNodesByTaskId',
export function findBackNodesByTaskId(data) {
  return request({
    url: `/flow/prod/api/findBackNodesByTaskId/${data.taskId}`,
    method: 'post',
  })
}

export function getFlowPlusActivityInfoByProcessInstanceIdAndActivityId(data) {
  return request({
    url: `/flow/bpmnDesigner/prod/api/getFlowPlusActivityInfoByProcessInstanceIdAndActivityId`,
    method: 'post',
    data
  })
}

export function getFlowCommentVosByProcessInstanceId(query) {
  return request({
    url: `/flow/prod/api/getFlowCommentVosByProcessInstanceId/${query.procInstId}`,
    method: 'post',
    data: {}
  })
}

export function getVariablesByProcessInstanceId(query) {
  return request({
    url: `/flow/query/getVariablesByProcessInstanceId/${query.procInstId}`,
    method: 'get',
    data: {}
  })
}
